package com.phpxiu.app.adapter;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.phpxiu.app.adapter.holder.HomeDiscoverViewHolder;
import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.LBSInfo;
import com.phpxiu.app.model.LiveRoomHost;
import com.phpxiu.app.model.list.HomeDiscover;

import java.util.List;

/**
 * Created by WuJinZhou on 2016/5/6.
 */
public class HomeDiscoverListAdapter extends BaseAdapter<HomeDiscover> {
    public final static String TAG="HomeDiscoverListAdapter";
    private String defaultPosition="";
    public HomeDiscoverListAdapter(Context context, List<HomeDiscover> list) {
        super(context,list);
        defaultPosition=context.getString(R.string.default_location);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HomeDiscover d=data.get(position);
        LiveRoomHost host=d.getHost();
        LBSInfo p=d.getLbs();
        HomeDiscoverViewHolder holder=null;
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.home_discover_list_item_view,null);
            holder=new HomeDiscoverViewHolder(convertView);
            convertView.setTag(holder);
        }

        holder=(HomeDiscoverViewHolder)convertView.getTag();
        holder.setDiscover(d);
        holder.head.setImageURI(Uri.parse(host.getAvatar()));
        //String t=d.getType();
//        if("3".equals(t)){
//            holder.stateIcon.setImageResource(R.mipmap.live_type_pay_icon);
//        }else if("2".equals(t)){
//            holder.stateIcon.setImageResource(R.mipmap.live_type_locked_icon);
//        }else{
//            holder.stateIcon.setImageResource(R.mipmap.live_type_public_icon);
//        }
        holder.stateIcon.setImageResource(R.mipmap.home_discover_live_state_icon);
        holder.online.setText(d.getOnlineCount());
        holder.nick.setText(host.getNickname());
        holder.topic.setText(host.getIntro());

        if(!TextUtils.isEmpty(p.getAddress())){
            holder.position.setText(p.getAddress());
        }else{
            holder.position.setText(defaultPosition);
        }

        holder.hideDivider(false);
        if(data.size()>0&&position==data.size()-1){
            holder.hideDivider(true);
        }
        return convertView;
    }
}
